//
//  foundQuestHeaderView.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/8/1.
//

#import "foundQuestHeaderView.h"
#import "TemplateFoundDetailsModel.h"
#import "YTBaseSelectStringView.h"

@interface foundQuestHeaderView ()

///删除按钮
@property (nonatomic ,strong) UIButton * removeBtn;

@property (nonatomic ,strong) UILabel * sourceFlagLab;

//收缩的按钮
@property (nonatomic ,strong) UIButton * sxBtn;
///配置
@property (nonatomic ,strong) YTBaseSelectStringView * pzView;
@property (nonatomic ,strong) UIView * oneview;
@property (nonatomic ,strong) UIView * tweview;
@property (nonatomic ,strong) UIView * threeview;
@property (nonatomic ,strong) UILabel * twelab;
@property (nonatomic ,strong) UILabel * threelab;
@property (nonatomic ,strong) UIView * buttomview;
@end

@implementation foundQuestHeaderView


+ (instancetype)NewView {
    foundQuestHeaderView * view = [foundQuestHeaderView new];
    view.clipsToBounds = YES;
    view.backgroundColor = UIColor.whiteColor;
    [view newUI];
    return view;
}
- (void)newUI{
    MJWeakSelf
    
    UIButton * sxBtn = [UIButton buttonWithType:0];
    self.sxBtn = sxBtn;
    sxBtn.addTarget(self,@selector(openSXBtnClick));
    [sxBtn setImage:[UIImage imageNamed:@"template_expand"] forState:UIControlStateNormal];
    [sxBtn setImage:[UIImage imageNamed:@"template_retract"] forState:UIControlStateSelected];
    [self addSubview:sxBtn];
    [sxBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(18));
        make.width.height.offset(kwt(20));
        make.right.offset(kwt(-14));
    }];
    
    UIButton * removeBtn = [UIButton buttonWithType:0];
    self.removeBtn = removeBtn;
    removeBtn.addTarget(self,@selector(scbtnClick));
    [removeBtn setImage:[UIImage imageNamed:@"task_delete1"] forState:UIControlStateNormal];
    [self addSubview:removeBtn];
    [removeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(15));
        make.width.height.offset(kwt(20));
        make.left.offset(kwt(10));
    }];
    
    UILabel * sourceFlagLab = [DTKTool labelWithText:@"-" andFont:kFont(19) andTextColor:KcolorHex(@"#222222")];
    self.sourceFlagLab = sourceFlagLab;
    [self addSubview:sourceFlagLab];
    [sourceFlagLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(removeBtn);
        make.left.offset(kwt(36));
    }];
    
    YTBaseSelectStringView * pzView = [YTBaseSelectStringView NewView];
    self.pzView = pzView;
    pzView.name = @"配置选项";
    pzView.forceFlag = YES;
    [self addSubview:pzView];
    pzView.block = ^(NSString * _Nonnull content) {
        if(weakSelf.openPZBlock){
            weakSelf.openPZBlock(weakSelf.model);
        }
    };
    [pzView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(45));
        make.right.offset(kwt(-10));
        make.left.offset(kwt(10));
        make.height.offset(kwt(60));
    }];
    
    UIView * buttomview = [UIView new];
    self.buttomview= buttomview;
    [self addSubview:buttomview];
    [DTKTool YJBK:kwt(5) andView:buttomview andWidth:0.5 andColor:KcolorHex(@"#D5D5D5")];
    [buttomview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(pzView.mas_bottom).offset(kwt(2));
        make.right.offset(kwt(-10));
        make.left.offset(kwt(10));
        make.height.offset(kwt(60));
    }];
    
    UIView * oneview = [UIView new];
    self.oneview = oneview;
    [buttomview addSubview:oneview];
    [oneview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.offset(0);
        make.width.offset(kwt(93));
    }];
    
    UILabel * onelab = [DTKTool labelWithText:@"池塘名称" andFont:kCFont(15) andTextColor:KcolorHex(@"#222222")];
    onelab.textAlignment = NSTextAlignmentCenter;
    [oneview addSubview:onelab];
    [onelab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.centerY.offset(kwt(-10));
    }];
    
    UIView * line = [UIView new];
    [oneview addSubview:line];
    line.backgroundColor = KcolorHex(@"#D5D5D5");
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.bottom.offset(0);
        make.width.offset(0.5);
    }];
    UIView * tweview = [UIView new];
    self.tweview = tweview;
    [buttomview addSubview:tweview];
    [tweview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.offset(0);
        make.width.offset(kwt(93));
        make.left.equalTo(oneview.mas_right);
    }];
    
    UILabel * twelab = [DTKTool labelWithText:@"--" andFont:kCFont(15) andTextColor:KcolorHex(@"#222222")];
    twelab.textAlignment = NSTextAlignmentCenter;
    self.twelab = twelab;
    [tweview addSubview:twelab];
    [twelab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.centerY.offset(kwt(-10));
    }];
    
    UIView * line1 = [UIView new];
    [tweview addSubview:line1];
    line1.backgroundColor = KcolorHex(@"#D5D5D5");
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.bottom.offset(0);
        make.width.offset(0.5);
    }];
    UIView * threeview = [UIView new];
    self.threeview = threeview;
    [buttomview addSubview:threeview];
    [threeview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.bottom.offset(0);
        make.left.equalTo(tweview.mas_right);
    }];
    UILabel * threelab = [DTKTool labelWithText:@"--" andFont:kCFont(15) andTextColor:KcolorHex(@"#222222")];
    threelab.textAlignment = NSTextAlignmentCenter;
    self.threelab = threelab;
    [threeview addSubview:threelab];
    [threelab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.centerY.offset(kwt(-10));
    }];
}


- (void)scbtnClick{
    if(self.openRemoveBlock){
        self.openRemoveBlock(self.model);
    }
}
- (void)openSXBtnClick{
    self.model.isSQ = !self.model.isSQ;
    if(self.openReloadBlock){
        self.openReloadBlock();
    }
}

- (void)setModel:(TemplateFoundDetailsTaskTypeModelListModel *)model {
    _model = model;
    self.sourceFlagLab.text = model.name;
    self.pzView.content = model.configureItem == 1?@"统一配置":@"分别配置";
    self.sxBtn.selected = model.isSQ;
    self.buttomview.hidden = YES;
//    self.sxBtn.hidden = model.taskItemModelList.count < 1;
    if(model.isBG){///表格绘制
        self.buttomview.hidden = NO;
        if(model.taskItemModelList.count > 1){///2个任务
            [self.oneview mas_updateConstraints:^(MASConstraintMaker *make) {
                make.width.offset(kwt(93));
            }];
            self.twelab.text = model.taskItemModelList.firstObject.name;
            [self.tweview mas_updateConstraints:^(MASConstraintMaker *make) {
                make.width.offset(kwt(131));
            }];
            self.threelab.text = model.taskItemModelList.lastObject.name;
            //            [self.threelab mas_updateConstraints:^(MASConstraintMaker *make) {
            //                make.width.offset(kwt(131));
            //            }];
        } else {///1个任务
            self.twelab.text = model.taskItemModelList.firstObject.name;
            [self.oneview mas_updateConstraints:^(MASConstraintMaker *make) {
                make.width.offset(kwt(177.5));
            }];
            [self.tweview mas_updateConstraints:^(MASConstraintMaker *make) {
                make.width.offset(kwt(177.5));
            }];
            //              [self.threelab mas_updateConstraints:^(MASConstraintMaker *make) {
            //                  make.width.offset(0);
            //              }];
        }
    }
    
    
}
@end
